
/**
 * 时间转换
 */
var formatDate = (value) => {
	let date = new Date(value);
	let y = date.getFullYear();
	let MM = date.getMonth() + 1;
	MM = MM < 10 ? "0" + MM : MM;
	let d = date.getDate();
	d = d < 10 ? "0" + d : d;
	let h = date.getHours();
	return y + "-" + MM + "-" + d;
}

var formatTime = (value) => {
	let date = new Date(value);
	let d = date.getDate();
	d = d < 10 ? "0" + d : d;
	let h = date.getHours();
	h = h < 10 ? "0" + h : h;
	let m = date.getMinutes();
	m = m < 10 ? "0" + m : m;
	let s = date.getSeconds();
	s = s < 10 ? "0" + s : s;
	return h + ":" + m + ":" + s;
}


// 记录当前页
var save_page = (that) => {
	sessionStorage.setItem('curr_page', that.page)
}

/**
* 获取七牛token
*/
var getQiNiuToken = (that) => {
	that.axios.post("/Qiniu/getToken", {}).then(data => {
		if (data) {
			// 处理成功的结果
			that.postData = {
				token: data.upToken,
			}
			that.domain = data.domain + '/';
		}
	})
}

/**
 * 获取可用优惠券
 */
var get_can_use_coupon = (that) => {
	that.axios.post("/Coupon/can_coupon", {
	}).then(data => {
		if (data) {
			that.can_use_coupon_list = data;
		}
	})
}


/**
 * 获取可用摄像头
 */
var get_can_camera_sec = (that) => {
	var form_data = {};
	form_data.status = 1;
	that.axios.post("/Car/get_camera", form_data).then(data => {
		if (data) {
			that.can_camera_list = data;
		}
	})
}

/**
 * 获取可用品种
 */
var get_can_use_variety = (that, type) => {
	that.axios.post("/Pet/get_variety", {
		type: type
	}).then(data => {
		if (data) {
			that.can_use_variety_list = data;
		}
	})
}

/**
 * 获取线下用户
 */
var get_user_list = (that) => {
	that.axios.post("/User/get_can_user", {
	}).then(data => {
		if (data) {
			that.can_use_user_list = data;
		}
	})
}

/**
 * 获取可用储值卡
 */
var get_stored_card_list = (that) => {
	that.axios.post("/order/get_stored_card", {
	}).then(data => {
		if (data) {
			that.can_use_stored_card_list = data;
		}
	})
}

/**
 * 获取可用计次卡
 */
var get_count_card_list = (that) => {
	that.axios.post("/order/get_count_card", {
	}).then(data => {
		if (data) {
			that.can_use_count_card_list = data;
		}
	})
}

/**
 * 获取可用车辆
 */
var get_car_list = (that, fn, type) => {
	that.axios.post("/order/get_car_list", {
	}).then(data => {
		if (data) {

			if (type == 1) {
				data.unshift({
					id: '0',
					name: '全部',
					car_sn: '全部'
				})
			}
			that.can_use_car_list = data;
			if (data.length > 0) {
				that.car_id = data[0].id;
			}
			if (fn) {
				fn();
			}
		}
	})
}


/**
 * 获取可用车辆(筛选)
 */
var get_search_car_list = (that) => {
	that.axios.post("/order/get_car_list", {
	}).then(data => {
		if (data) {
			that.can_use_car_list = data;
		}
	})
}


/**
 * 获取可用的服务人员
 */
var get_service_list = (that, fn) => {
	that.axios.post("/order/get_service_user", {
	}).then(data => {
		if (data) {
			that.can_service_user_list = data;
			if (fn) {
				fn();
			}
		}
	})
}

/**
 * 获取可用的区域
 */
var get_area_list = (that) => {
	that.axios.post("/index/get_area", {
	}).then(data => {
		if (data) {
			that.can_area_list = data;
		}
	})
}


/**
 * 获取可用的附加服务
 */
var get_can_use_service_list = (that, page, limit, id, search_key) => {
	var form_data = {};
	form_data.page = page;
	form_data.limit = limit;
	form_data.variety_id = id;
	if (search_key) {
		form_data.key = search_key;
	}
	that.axios.post("/Service/can_use_list", form_data).then(data => {
		if (data) {
			that.can_use_service_list = data.list;
			that.can_use_service_count = data.count;
		}
	})
}

/**
 * 获取可用的服务
 */
var get_can_use_all_service_list = (that, page, limit, type, id, variety_id, key) => {
	var form_data = {};
	form_data.page = page;
	form_data.limit = limit;
	console.log(key)
	if (type) {
		form_data.type = type;
	}
	if (id) {
		form_data.variety_id = id;
	}
	if (variety_id) {
		form_data.variety_id = variety_id;
	}
	if (key) {
		form_data.key = key;
	}
	that.axios.post("/Coupon/service_list", form_data).then(data => {
		if (data) {
			that.can_all_service_list = data.list;
			that.can_all_service_count = data.count;
		}
	})
}

/**
 * 获取可用的服务优惠券
 */
var get_can_use_service_coupon_list = (that, page, limit, status, key) => {
	var form_data = {};
	form_data.page = page;
	form_data.limit = limit;
	if (status) {
		form_data.status = status;
	}
	if (key) {
		form_data.key = key;
	}
	that.axios.post("/Stored_card/coupon_list", form_data).then(data => {
		if (data) {
			that.can_service_coupon_list = data.list;
			that.can_service_coupon_count = data.count;
		}
	})
}

export default {
	formatTime,
	formatDate,
	save_page,
	getQiNiuToken,
	get_can_use_coupon,
	get_can_camera_sec,
	get_can_use_variety,
	get_user_list,
	get_stored_card_list,
	get_count_card_list,
	get_car_list,
	get_service_list,
	get_area_list,
	get_search_car_list,
	get_can_use_service_list,
	get_can_use_all_service_list,
	get_can_use_service_coupon_list
}
